const express = require('express')

const app = express()

app.use((req, res, next) => {
  const referer = req.get('referer')
  if(referer) {
    const url = new URL(referer)
    console.log('hostname', url.hostname)
    if(url.hostname !== '127.0.0.1') {
      res.status(404).send('404不让你访问')
      return
    }
  }
  next()
})
app.use(express.static(__dirname))

app.get('/', (req, res) => {
  res.send('首页')
})

app.all('*url', (req, res) => {
  res.send('404找不到资源')
})

app.listen(9000, () => {
  console.log('服务已启动，9000端口监听中。。。')
})